package car;

import java.awt.*;
import java.awt.geom.Arc2D;
import java.awt.geom.Area;

public class RingPanel {
    private static final int DEFAULT_INNER_RADIUS_OFFSET = 20;

    public static void drawRingPanel(Graphics2D g2, int x, int y, int width, int height, int max, int value, Color fillColor) {
        int outerRadius = width / 2;
        int innerRadius = outerRadius - DEFAULT_INNER_RADIUS_OFFSET;

        g2.setColor(Color.BLACK);
        g2.drawOval(x, y, width, height);

        g2.setColor(Color.BLACK);
        g2.drawOval(x + (outerRadius - innerRadius), y + (outerRadius - innerRadius), innerRadius * 2, innerRadius * 2);

        double sweepAngle = (value / (double) max) * 360;

        Arc2D outerArc = new Arc2D.Float(x, y, width, height, -90, (float) sweepAngle, Arc2D.PIE);
        Arc2D innerArc = new Arc2D.Float(x + (outerRadius - innerRadius), y + (outerRadius - innerRadius), innerRadius * 2, innerRadius * 2, -90, (float) sweepAngle, Arc2D.PIE);


        Area ringArea = new Area(outerArc);
        ringArea.subtract(new Area(innerArc));

        g2.setColor(fillColor);
        g2.fill(ringArea);
    }
}
